$(function(){
//单据添加
$('.add_order_doubt').click(function(){
	var url = 'ordermanage-add_order_doubt';
	var data = http_to_request(url);
	
	layer.open({
		type: 1,
		title: '添加可疑单据',
		area: ['1000px', '672px'],
		// area: ['900px', '672px'],
		shade: 0.3,
		shadeClose: true,
		offset: '40px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
	  }
	});
})

//面单添加
$('.add_order_singleplane').click(function(){
	var url = 'ordermanage-add_order_singleplane';
	var data = http_to_request(url);
	
	layer.open({
		type: 1,
		title: '添加面单',
		area: ['1000px', '692px'],
		shade: 0.3,
		shadeClose: true,
		offset: '40px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
	  }
	});
})


//从TXT文件添加
$('.txt_upload').click(function(){
	var url = 'ordermanage-txt_upload';
	var data = http_to_request(url);
	
	layer.open({
		type: 1,
		title: '从TXT文件——添加',
		area: ['1000px', '672px'],
		// area: ['900px', '672px'],
		shade: 0.3,
		shadeClose: true,
		offset: '20px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
	  }
	});
})                




//excel文件上传
$('.file_upload').click(function(){
	var url = 'ordermanage-file_upload';
	var data = http_to_request(url);
	
	layer.open({
		type: 1,
		title: '从Excel文件导入——添加',
		area: ['900px', '672px'],
		shade: 0.3,
		shadeClose: true,
		offset: '20px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
	  }
	});
})
//单据指派
$('.distribute_task').on('click',function(){

	var tr = $('.tablediv_cj_data tbody').find('tr[class="active"]');
	if(tr.length == 0){
		layer.msg('请选择要指派的单据', {icon: 2});
		return false;
	}
	
	var orderids = '';
	$.each(tr,function(k,v){
		var id = $(v).find('span').attr('str_id');
		orderids += id+',';
	})
	orderids = orderids.substring(0,orderids.length-1);
	console.log(orderids);
	var parameter = 'orderids='+orderids;
	var url = 'ordermanage-distribute_task';
	var data = http_to_request(url,parameter);
	
	layer.open({
		type: 1,
		title: '单据指派',
		area: ['900px', '81%'],
		// area: ['900px', '692px'],
		shade: 0.3,
		shadeClose: true,
		offset: '40px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
	  }
	});
})

//单据转发
$('.huitui').on('click',function(event){
	var tr = $(this).parents('tr');
	var id = $(this).attr('attr_id');//获取单号
	var url = 'ordermanage-task_back';
	var parameter = 'id='+id;
	
	/*layer.confirm('确定要转发该单据吗？', {
			btn: ['是','否'] //按钮
		}, function(){
			var data = http_to_request(url,parameter);
			layer.closeAll();
			$('#querybtn[link="ordermanage-orderlist"]').click();
		}, function(){
			
		});*/
	var data = http_to_request(url,parameter);	
	layer.open({
		type: 1,
		title: '单据转发',
		area: ['1000px', '81%'],
		zIndex: 0,
		shade: 0.3,
		shadeClose: true,
		offset: '40px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
			return false;
	  }
	});
	event.stopPropagation();
})
	


//已完成的数据详情
$(".doubtdetails").on("click",function(event){
	var id = $(this).attr('attr_id');
	var url = 'ordermanage-doubtdetails';
	var parameter = 'id='+id;
	
	var data = http_to_request(url,parameter);
	
	layer.open({
		type: 1,
		title: '处理详情',
		area: ['1000px', '692px'],
		zIndex: 0,
		shade: 0.3,
		shadeClose: true,
		offset: '40px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
			return false;
	  }
	});

	event.stopPropagation();
		
});

//未处理单据的物流详情
$(".undone_doubtdetails").on("click",function(event){
	var id = $(this).attr('attr_id');        //物流id
	var number = $(this).attr('number');     //物流单号 
    var express = $(this).attr('express');   //物流公司名称
// 	alert('id='+id+' status='+status+' express='+express);return false;
	var url = 'ordermanage-wl_doubtdetails';
	var parameter = 'id='+id+'&express='+express+'&number='+number;
	
	var data = http_to_request(url,parameter);
	
	layer.open({
		type: 1,
		title: '处理详情',
		area: ['1000px', '81%'],
		// area: ['1000px', '692px'],
		zIndex: 0,
		shade: 0.3,
		shadeClose: true,
		offset: '40px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
			return false;
	  }
	});

	event.stopPropagation();
		
});



//数据补全
$(".completion").on("click",function(event){
	var id = $(this).attr('attr_id');
	var url = 'ordermanage-completion';
	var parameter = 'id='+id;
	
	var data = http_to_request(url,parameter);
	
	layer.open({
		type: 1,
		title: '数据补全',
		area: ['1000px', '692px'],
		
		shade: 0.3,
		shadeClose: true,
		offset: '40px',
		maxmin: false,
		content: data,
		success:function(){
			layer.closeAll('loading'); //关闭加载层
			return false;
	  }
	});

	event.stopPropagation();
	
		
});

	//数据删除
$(".delete_numbers").on("click",function(event){

	var cur_page = $('.fenyes_lt .pager .active').attr('attr_page');	//当前页数
	var id = $(this).attr('attr_id');
	var url = 'ordermanage-delete_numbers';
	var parameter = 'id='+id;
	
	layer.confirm('<div style="color:red"v>确定要删除该单据吗？</div>', {
			btn: ['是','否'] //按钮
		}, function(){
			var data = http_to_request(url,parameter);
			
			var formdata = $('#querybtn[link="ordermanage-orderlist"]').parent().serialize()+'&cur_page='+cur_page;	//表单序列化
			var link = $('#querybtn[link="ordermanage-orderlist"]').attr('link');
			var idkeynum = $('#querybtn[link="ordermanage-orderlist"]').closest(".cjall").attr('idkeynum');
			parent.find_data(link,formdata,cur_page,idkeynum);
			layer.closeAll();
			// $('#querybtn[link="ordermanage-orderlist"]').click();
		}, function(){
			
		});	

	event.stopPropagation();
		
});


$('.table-hover tr').on('click',function(){
	var t = $(this).find('input[name="discusess_type"]').val();

	if(t != 0){
		if(t == 1){
			layer.msg('已分配，不能重复分配',{time:1500,icon:2});
			return false;
		}else{
			layer.msg('不可分配其他市的订单',{time:1500,icon:2});
			return false;
		}
	}
	
})


})